﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GmFamilyCustomData.h"
#include "IParameterCustomData.h"
#include "NdbDataSchema.h"
#include "NdbObjectSchematic.h"

#define RAILING_CUSTOM_DATA_ID      L"RailingCustomDataId"

namespace gcmp
{
    class ElementId;
    class ICurve2d;
}

namespace bm
{
    //截断位置（支柱）样式
    enum class EnCutPosStyle : int32_t
    {
        CPS_NONE = 0,                   // 从不
        CPS_ENDOF,                      // 每段扶手末端
        CPS_ANGLEBIG                    // 角度大于方式
    };

    //对齐样式
    enum class EnAlignStyle : int32_t
    {
        AS_START = 0,                   // 起点对齐
        AS_CENTER,                      // 中心对齐
        AS_END,                         // 终点对齐
        AS_EXPAND                       // 展开样式以匹配，均分展开
    };

    enum class EnRailingPlaceMode : int32_t
    {
        RAILING_DRAW_ON_WORKPLANE = 0,  // 工作平面上绘制
        RAILING_PLACE_ON_STAIR,         // 放置于楼梯
        RAILING_PLACE_ON_STAIR_BEAM     // 放置于楼梯梯梁
    };

    // 迹线信息
    class GM_FAMILY_CUSTOM_DATA_EXPORT TracesCurveData : public gcmp::NdbObjectSchematic
    {
        CANNOT_COPY_OR_ASSIGN(TracesCurveData)
        DATA_BEGIN(bm, TracesCurveData, gcmp::NdbObjectSchematic, AEA735CA - EFC9 - 4197 - 9B00 - 12917FEAFD38, gmfamilycustomdata)
            DATA(gcmp::OwnerPtr<gcmp::ICurve2d>, TracesCurve);
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)

        DATA_END

    public:
        TracesCurveData(const gcmp::ICurve2d* pTracesCurve);
        virtual ~TracesCurveData() {}

    public:
        bool SetOwnerElement(gcmp::IElement* pOwnerElement) { m_pOwnerElement = pOwnerElement; return true; }

        const gcmp::ICurve2d* GetTracesCurve() const { return GetTracesCurve__().get(); }
        void SetTracesCurve(gcmp::OwnerPtr<gcmp::ICurve2d> opCurve2d) { return SetTracesCurve__(TransferOwnership(opCurve2d)); }

        bool IsLessThan(const TracesCurveData* pOther) const;
        bool HasSameValue(const TracesCurveData* pOther) const;
        gcmp::OwnerPtr<TracesCurveData> Clone() const;

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;

    };

    //栏杆扶手自定义数据
    class GM_FAMILY_CUSTOM_DATA_EXPORT RailingCustomData : public gcmp::IParameterCustomData
    {
    private:
        CANNOT_COPY_OR_ASSIGN(RailingCustomData);
        DATA_BEGIN(bm, RailingCustomData, gcmp::NdbObjectSchematic, 0C48B1F0 - 6E4D - 4B3A - 9659 - 8D88772BF5C6, gmfamilycustomdata)
            ARR_DATA(gcmp::OwnerPtr<TracesCurveData>, TracesCurveDatas)
            DATA(EnCutPosStyle, CutPosStyle)
            DATA(double, CutPosStyleAngle)
            DATA(EnAlignStyle, AlignStyles)
            DATA(EnRailingPlaceMode, PlaceMode)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)
        DATA_END

    public:
        virtual ~RailingCustomData() {}

        bool AddTracesCurveData(gcmp::OwnerPtr<TracesCurveData> curve);

        bool SetOwnerElement(gcmp::IElement* pOwnerElement)
        { 
            m_pOwnerElement = pOwnerElement; 
            for (size_t i =0 ;i<m_TracesCurveDatas.size(); i++)
            {
                if(m_TracesCurveDatas[i])
                    m_TracesCurveDatas[i]->SetOwnerElement(pOwnerElement);
            }
            return true;
        }

    public:
        void SetTracesCurveDatas(std::vector<gcmp::OwnerPtr<TracesCurveData>>&& curveDatas);
        std::vector<gcmp::OwnerPtr<TracesCurveData>>& GetTracesCurveDatas() { return GetTracesCurveDatasFW__(); }
        const std::vector<gcmp::OwnerPtr<TracesCurveData>>& GetTracesCurveDatas() const { return GetTracesCurveDatas__(); }

        //截断位置样式
        void SetCutPosStyle(const EnCutPosStyle& style) { SetCutPosStyle__(style); }
        const EnCutPosStyle GetCutPosStyle() const { return GetCutPosStyle__(); }
        EnCutPosStyle GetCutPosStyle() { return GetCutPosStyle__(); }

        //截断位置角度（与角度大于样式一起使用, 默认为0）
        void SetCutPosStyleAngle(const double& angle) { SetCutPosStyleAngle__(angle); }
        const double GetCutPosStyleAngle() const { return GetCutPosStyleAngle__(); }
        double GetCutPosStyleAngle() { return GetCutPosStyleAngle__(); }

        //对齐样式:起点对齐；终点对齐，中点对齐
        void SetAlignStyle(const EnAlignStyle& style) { SetAlignStyles__(style); }
        const EnAlignStyle GetAlignStyle() const { return GetAlignStyles__(); }
        EnAlignStyle GetAlignStyle() { return GetAlignStyles__(); }

        //楼梯放置模式
        void SetPlaceMode(const EnRailingPlaceMode& mode) { SetPlaceMode__(mode); }
        const EnRailingPlaceMode GetPlaceMode() const { return GetPlaceMode__(); }
        EnRailingPlaceMode GetPlaceMode() { return GetPlaceMode__(); }

    public:
        virtual bool IsLessThan(const gcmp::IParameterCustomData* pOther) const override;
        virtual bool HasSameValue(const gcmp::IParameterCustomData* pOther) const override;
        virtual std::wstring GetCustomDataId() const override;
        virtual Int32 GetVersion() const override;
        virtual gcmp::OwnerPtr<gcmp::IParameterCustomData> Clone() const override;
        virtual void GetReferencedElementIds(std::vector<gcmp::ElementId>& referenceElementIds) const override;

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;

    };
}
